﻿#include "SEAAreaJunctionDialog.h"
#include "ui_SEAAreaJunctionDialog.h"
#include "SEAJunctionUserDefWidget.h"
#include "SEAAreaLeakDialog.h"

#include "OperatorsInterface/ParaWidgetInterfaceOperator.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKCore/FITKVec3D.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSys.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEAAbstractJunction.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEAJunctionArea.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscNodeList.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysGeoProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsShellPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbstractSpectra.h"

#include <QList>
#include <QMessageBox>

#define SEAAreaJunction_SubSysPos Qt::UserRole
#define SEAAreaJunction_DefineStrPos Qt::UserRole+1

Q_DECLARE_METATYPE(Acoustics::FITKSEAJunAreaLeakStr)

namespace GUI
{
    SEAAreaJunctionDialog::SEAAreaJunctionDialog(int dataID, EventOper::ParaWidgetInterfaceOperator * oper, bool isCreate):
        GUIJunctionDialogBase(dataID, oper, isCreate, FITKAPP->getGlobalData()->getMainWindow())
    {
        _ui = new Ui::SEAAreaJunctionDialog();
        _ui->setupUi(this);

        if (isCreate == false) {
            _currentDataID = dataID;
        }

        init();
    }

    SEAAreaJunctionDialog::~SEAAreaJunctionDialog()
    {
        if (_userDefWidget) {
            delete _userDefWidget;
            _userDefWidget = nullptr;
        }
        if (_ui) {
            delete _ui;
            _ui = nullptr;
        }
    }

    void SEAAreaJunctionDialog::init()
    {
        if (_physics == nullptr)return;
        QStringList connectHeader;
        connectHeader << QString(tr("Connections"));
        _ui->tableWidget_Connect->setColumnCount(1);
        _ui->tableWidget_Connect->setHorizontalHeaderLabels(connectHeader);
        //自适应
        _ui->tableWidget_Connect->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
        //隐藏行表头
        _ui->tableWidget_Connect->verticalHeader()->setVisible(false);

        _ui->checkBox_Resonant->setChecked(true);
        _ui->checkBox_Nonresonant->setChecked(true);
        _ui->checkBox_Leaks->setChecked(true);
        _ui->checkBox_TransmissionLoss->setChecked(false);
        _ui->comboBox_Spectrum->setEnabled(false);
        _ui->comboBox_Driection->setEnabled(false);
        _ui->lineEdit_AreaAcoustic->setEnabled(false);
        _ui->checkBox_EnabledJunction->setChecked(true);
        _ui->lineEdit_AreaRadiation->setEnabled(false);
        _ui->lineEdit_PerimeterRadiation->setEnabled(false);

        Acoustics::FITKAcousticsSpectraManager* spectraMan = _physics->getFITKAcousticsSpectraManager();
        if (spectraMan) {
            for (auto spectra : spectraMan->getSpectraByType(Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::TransmissionLoss)) {
                if(spectra == nullptr)continue;
                _ui->comboBox_Spectrum->addItem(spectra->getDataObjectName(), spectra->getDataObjectID());
            }
            if (_ui->comboBox_Spectrum->count() > 0)_ui->comboBox_Spectrum->setCurrentIndex(0);
        }
            

        QStringList defineHeader;
        defineHeader << QString(tr("Name")) << QString(tr("Enabled")) << QString(tr("Type")) << QString(tr("Length")) << QString(tr("Width"))
            << QString(tr("Radius")) << QString(tr("Depth")) << QString(tr("Area")) << QString(tr("TL Spectrum"));
        _ui->tableWidget_Define->setColumnCount(9);
        _ui->tableWidget_Define->setHorizontalHeaderLabels(defineHeader);
        //自适应
        //_ui->tableWidget_Define->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

        _userDefWidget = new SEAJunctionUserDefWidget(this);
        _ui->gridLayout_UserDefined->addWidget(_userDefWidget);

        _ui->label_RadiationImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaRadiation.png"));
        _ui->label_CircularImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaCircular.png"));
        _ui->label_Rectangularimage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaRectangular.png"));
        _ui->label_SlitImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaSlit.png"));
        _ui->label_UserdefinedImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaUserDefined.png"));

        if (_isCreate) {
            InitCreate();
            setWindowTitle(QString("SEA Area Junction Create"));
        }
        else {
            InitEdit();
            setWindowTitle(QString("SEA Area Junction Edit"));
            _ui->lineEdit_Name->setEnabled(false);
        }
    }

    void SEAAreaJunctionDialog::setSubSysIDs(QList<int>& subSysIDs)
    {
        if (_SEAModel == nullptr)return;
        if (_SEAModel->getSEASubSysManager() == nullptr)return;

        int shellID = -1;
        QList<Acoustics::FITKSEAJunAreaConStr> strList = {};
        for (int sysSubId : subSysIDs) {
            Acoustics::FITKAbstractSEASubSys* shellData = _SEAModel->getSEASubSysManager()->getDataByID(sysSubId);
            if (shellData == nullptr)continue;
            switch (shellData->getSEASubSysType()){
            case Acoustics::FITKAbstractSEASubSys::SEABeam:
            case Acoustics::FITKAbstractSEASubSys::SEAFlatPlate:
            case Acoustics::FITKAbstractSEASubSys::SEASinglyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEADoublyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEACylinderShell: {
                shellID = sysSubId;
                break;
            }
            }
            Acoustics::FITKSEAJunAreaConStr str;
            str._subSysID = sysSubId;
            strList.append(str);
        }
        updateConnectTable(strList);
        initDirectionComboBoxItem(subSysIDs);
        initGeneralImage(subSysIDs);
        initGeoPro(shellID);

        if (_userDefWidget) {
            _userDefWidget->initTable(subSysIDs);
        }
    }

    void SEAAreaJunctionDialog::on_pushButton_Ok_clicked()
    {
        if (_isCreate) {
            if (OKCreate() == false)return;
        }
        else {
            if (OKEdit() == false)return;
        }
        if (_oper) {
            _oper->setArgs(objID_String, _currentDataID);
            _oper->execProfession();
        }
        this->accept();
    }

    void SEAAreaJunctionDialog::on_pushButton_Cancel_clicked()
    {
        this->reject();
    }

    void GUI::SEAAreaJunctionDialog::on_pushButton_Add_clicked()
    {
        //调用对话框
        Acoustics::FITKSEAJunAreaLeakStr newStr;
        SEAAreaLeakDialog dialog(newStr);
        if (dialog.exec() != QDialog::Accepted)return;
        newStr = dialog.getData();

        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = getLeaksTable();
        leakStrList.append(newStr);
        updateLeaksTable(leakStrList);
    }

    void GUI::SEAAreaJunctionDialog::on_pushButton_Duplicate_clicked()
    {
        int currentRow = _ui->tableWidget_Define->currentRow();
        QTableWidgetItem* item = _ui->tableWidget_Define->item(currentRow, 0);
        if (item == nullptr)return;
        Acoustics::FITKSEAJunAreaLeakStr str = item->data(SEAAreaJunction_DefineStrPos).value<Acoustics::FITKSEAJunAreaLeakStr>();
        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = getLeaksTable();
        leakStrList.append(str);
        updateLeaksTable(leakStrList);
    }

    void GUI::SEAAreaJunctionDialog::on_pushButton_Edit_clicked()
    {
        int currentRow = _ui->tableWidget_Define->currentRow();
        QTableWidgetItem* item = _ui->tableWidget_Define->item(currentRow, 0);
        if (item == nullptr)return;
        Acoustics::FITKSEAJunAreaLeakStr str = item->data(SEAAreaJunction_DefineStrPos).value<Acoustics::FITKSEAJunAreaLeakStr>();
        SEAAreaLeakDialog dialog(str);
        if (dialog.exec() != QDialog::Accepted)return;
        str = dialog.getData();
        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = getLeaksTable();
        if (currentRow >= leakStrList.size())return;
        leakStrList[currentRow] = str;
        updateLeaksTable(leakStrList);
    }

    void GUI::SEAAreaJunctionDialog::on_pushButton_Delete_clicked()
    {
        int currentRow = _ui->tableWidget_Define->currentRow();
        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = getLeaksTable();
        if (currentRow < 0 || (currentRow > leakStrList.size() - 1))return;
        leakStrList.removeAt(currentRow);
        updateLeaksTable(leakStrList);
    }

    void SEAAreaJunctionDialog::on_checkBox_TransmissionLoss_clicked()
    {
        bool isCheck = _ui->checkBox_TransmissionLoss->isChecked();
        _ui->comboBox_Spectrum->setEnabled(isCheck);
        _ui->comboBox_Driection->setEnabled(isCheck);
    }

    void SEAAreaJunctionDialog::InitCreate()
    {
        if (_DiscModel == nullptr && _DiscModel->getJunctionManager() == nullptr)return;
        QString name = "Area-0";
        name = _DiscModel->getJunctionManager()->checkName(name);
        _ui->lineEdit_Name->setText(name);
    }

    void SEAAreaJunctionDialog::InitEdit()
    {
        if (_DiscModel == nullptr && _DiscModel->getJunctionManager() == nullptr)return;
        Acoustics::FITKSEAJunctionArea* junData = dynamic_cast<Acoustics::FITKSEAJunctionArea*>(_DiscModel->getJunctionManager()->getDataByID(_currentDataID));
        if (junData == nullptr)return;
        QString name = junData->getDataObjectName();
        _ui->lineEdit_Name->setText(name);

        setDataToWidget(junData);
    }

    bool SEAAreaJunctionDialog::OKCreate()
    {
        if (_DiscModel == nullptr && _DiscModel->getJunctionManager() == nullptr)return false;
        QString name = _ui->lineEdit_Name->text();
        if (_DiscModel->getJunctionManager()->getDataByName(name)) {
            QMessageBox box(QMessageBox::Warning, "", QString(tr("\"%1\" Name exists!")).arg(name), QMessageBox::Ok);
            box.exec();
            return false;
        }

        Acoustics::FITKSEAJunctionArea* junData = new Acoustics::FITKSEAJunctionArea();
        junData->setDataObjectName(name);
        junData->setAutoCreate(false);
        _currentDataID = junData->getDataObjectID();
        getDataFromWidget(junData);
        _DiscModel->getJunctionManager()->appendDataObj(junData);
        return true;
    }

    bool SEAAreaJunctionDialog::OKEdit()
    {
        if (_DiscModel == nullptr && _DiscModel->getJunctionManager() == nullptr)return false;
        //QString name = _ui->lineEdit_Name->text();
        //if (_DiscModel->getJunctionManager()->getDataByName(name)) {
        //    QMessageBox box(QMessageBox::Warning, "", QString(tr("\"%1\" Name exists!")).arg(name), QMessageBox::Ok);
        //    box.exec();
        //    return false;
        //}
        auto junData = dynamic_cast<Acoustics::FITKSEAJunctionArea*>(_DiscModel->getJunctionManager()->getDataByID(_currentDataID));
        if (junData == nullptr)return false;
        //junData->setDataObjectName(name);
        getDataFromWidget(junData);
        return true;
    }

    void SEAAreaJunctionDialog::getDataFromWidget(Acoustics::FITKSEAJunctionArea * data)
    {
        if (data == nullptr || _userDefWidget == nullptr)return;
        data->setIsUseResonant(_ui->checkBox_Resonant->isChecked());
        data->setIsUseNonresonant(_ui->checkBox_Nonresonant->isChecked());
        data->setIsUseLeak(_ui->checkBox_Leaks->isChecked());
        data->setIsUseTransmissionLoss(_ui->checkBox_TransmissionLoss->isChecked());
        data->setSpectrum(_ui->comboBox_Spectrum->currentData().toInt());
        if (_ui->comboBox_Driection->currentData() == 0)  data->setDirection(Acoustics::FITKSEAJunctionArea::From);
        else data->setDirection(Acoustics::FITKSEAJunctionArea::To);

        QList<Acoustics::FITKSEAJunAreaConStr> strList = {};
        for (int i = 0; i < _ui->tableWidget_Connect->rowCount(); i++) {
            Acoustics::FITKSEAJunAreaConStr str;
            QTableWidgetItem* item = _ui->tableWidget_Connect->item(i, 0);
            if (item) {
                str._subSysID = item->data(SEAAreaJunction_SubSysPos).toInt();
            }
            strList.append(str);
        }
        data->replaceConnections(strList);

        data->setAcousticCouplingAreaX(_ui->lineEdit_XAcoustic->text().toDouble());
        data->setEnabledJunction(_ui->checkBox_EnabledJunction->isChecked());
        data->setAcousticRadiationAreaX(_ui->lineEdit_XAreaRadiation->text().toDouble());
        data->setAcousticRadiationPerimaterX(_ui->lineEdit_XPerimeter->text().toDouble());
        
        //存储渗漏信息
        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = getLeaksTable();
        data->replaceLeaks(leakStrList);

        //存储user-defined界面数据
        _userDefWidget->getDataFromWidget(data);
    }

    void SEAAreaJunctionDialog::setDataToWidget(Acoustics::FITKSEAJunctionArea * data)
    {
        if (data == nullptr || _userDefWidget == nullptr)return;
        _ui->checkBox_Resonant->setChecked(data->getIsUseResonant());
        _ui->checkBox_Nonresonant->setChecked(data->getIsUseNonresonant());
        _ui->checkBox_Leaks->setChecked(data->getIsUseLeak());
        _ui->checkBox_TransmissionLoss->setChecked(data->getIsUseTransmissionLoss());
        if (data->getIsUseTransmissionLoss() == true) {
            _ui->comboBox_Spectrum->setEnabled(true);
            _ui->comboBox_Driection->setEnabled(true);
        }
        _ui->comboBox_Spectrum->setCurrentIndex(_ui->comboBox_Spectrum->findData(data->getSpectrum()));

        //初始化图片
        initGeneralImage(data->getSubSysIds());

        //初始化选项
        initDirectionComboBoxItem(data->getSubSysIds());
        switch (data->getDirection()){
        case Acoustics::FITKSEAJunctionArea::From:_ui->comboBox_Driection->setCurrentIndex(0); break;
        case Acoustics::FITKSEAJunctionArea::To:_ui->comboBox_Driection->setCurrentIndex(1); break;
        }

        //更新连接表格
        QList<Acoustics::FITKSEAJunAreaConStr> areaConStr = data->getConnections();
        updateConnectTable(areaConStr);

        _ui->checkBox_EnabledJunction->setChecked(data->getEnabledJunction());

        _ui->lineEdit_XAcoustic->setText(QString::number(data->getAcousticCouplingAreaX()));
        _ui->lineEdit_XAreaRadiation->setText(QString::number(data->getAcousticRadiationAreaX()));
        _ui->lineEdit_XPerimeter->setText(QString::number(data->getAcousticRadiationPerimaterX()));

        QList<Acoustics::FITKSEAJunAreaLeakStr> define = data->getLeaks();
        updateLeaksTable(define);

        int shellID = data->getConnectionShellID();
        initGeoPro(shellID);

        //初始化user-defined界面
        _userDefWidget->initTable(data->getSubSysIds());
        //user-defined中填充数据
        _userDefWidget->setDataToWidget(data);
    }

    void SEAAreaJunctionDialog::initDirectionComboBoxItem(const QList<int>& subSysList)
    {
        _ui->comboBox_Driection->clear();
        if (_SEAModel == nullptr && _SEAModel->getSEASubSysManager() == nullptr)return;
        QStringList cavityNames = {};
        QString shellName = "";
        for (int subSysID : subSysList) {
            Acoustics::FITKAbstractSEASubSys* subSys = _SEAModel->getSEASubSysManager()->getDataByID(subSysID);
            if(subSys == nullptr)continue;
            auto type = subSys->getSEASubSysType();
            switch (type){
            case Acoustics::FITKAbstractSEASubSys::SEAFlatPlate:
            case Acoustics::FITKAbstractSEASubSys::SEASinglyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEADoublyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEACylinderShell: {
                shellName = subSys->getDataObjectName();
                break;
            }
            case Acoustics::FITKAbstractSEASubSys::SEACavity: {
                cavityNames.append(subSys->getDataObjectName());
                break;
            }
            }
        }

        QString fromItem = "", toItem = "";
        if (cavityNames.size() == 1) {
            fromItem = QString("From %1").arg(cavityNames[0]);
            toItem = QString("To %1").arg(cavityNames[0]);
        }
        else if (cavityNames.size() == 2) {
            fromItem = QString("From %1 to %2").arg(cavityNames[0]).arg(cavityNames[1]);
            toItem = QString("From %1 to %2").arg(cavityNames[1]).arg(cavityNames[0]);
        }

        _ui->comboBox_Driection->addItem(fromItem, QVariant::fromValue(Acoustics::FITKSEAJunctionArea::JunctionAreaDirection::From));
        _ui->comboBox_Driection->addItem(toItem, QVariant::fromValue(Acoustics::FITKSEAJunctionArea::JunctionAreaDirection::To));
        _ui->comboBox_Driection->setCurrentIndex(0);
    }

    void SEAAreaJunctionDialog::initGeneralImage(const QList<int>& subSysList)
    {
        if (_SEAModel == nullptr && _SEAModel->getSEASubSysManager() == nullptr)return;
        int cavityNum = 0, shellNum = 0;
        for (int subSysID : subSysList) {
            Acoustics::FITKAbstractSEASubSys* subSys = _SEAModel->getSEASubSysManager()->getDataByID(subSysID);
            if (subSys == nullptr)continue;
            auto type = subSys->getSEASubSysType();
            switch (type) {
            case Acoustics::FITKAbstractSEASubSys::SEAFlatPlate:
            case Acoustics::FITKAbstractSEASubSys::SEASinglyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEADoublyCurvedShell:
            case Acoustics::FITKAbstractSEASubSys::SEACylinderShell: {
                shellNum++;
                break;
            }
            case Acoustics::FITKAbstractSEASubSys::SEACavity: {
                cavityNum++;
                break;
            }
            }
        }

        if (shellNum != 0 && cavityNum == 1) {
            _ui->label_GeneralImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaGeneral_cavity_shell.png"));
        }
        else if (shellNum != 0 && cavityNum > 1 ) {
            _ui->label_GeneralImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaGeneral_cavity_shell_cavity.png"));
        }
        else if (shellNum == 0 && cavityNum > 1) {
            _ui->label_GeneralImage->setPixmap(QPixmap(":/icons/SEA_Junction_AreaGeneral_cavity_cavity.png"));
        }
    }

    void SEAAreaJunctionDialog::initGeoPro(int shellID)
    {
        if (_SEAModel == nullptr)return;
        if (_SEAModel->getSEASubSysManager() == nullptr)return;

        //获取面积与perimeter
        double area = 0.0, perimeter = 0.0;
        Acoustics::FITKAbstractSEASubSys* shellData = _SEAModel->getSEASubSysManager()->getDataByID(shellID);
        if (shellData && shellData->getGeoProp()) {
            Acoustics::FITKSEASubSysGeoProp* shellGeoPro = shellData->getGeoProp();
            area = shellGeoPro->getGeoProp(Acoustics::FITKSEASubSysGeoProp::GeoPropType::Area);
            perimeter = shellGeoPro->getGeoProp(Acoustics::FITKSEASubSysGeoProp::GeoPropType::Circumference);
        }
        _ui->lineEdit_AreaAcoustic->setText(QString::number(area));
        _ui->lineEdit_AreaRadiation->setText(QString::number(area));
        _ui->lineEdit_PerimeterRadiation->setText(QString::number(perimeter));
    }

    void SEAAreaJunctionDialog::updateConnectTable(QList<Acoustics::FITKSEAJunAreaConStr>& junction)
    {
        if (_SEAModel == nullptr && _SEAModel->getSEASubSysManager() == nullptr) false;
        _ui->tableWidget_Connect->setRowCount(0);
        int rowIndex = 0;
        for (Acoustics::FITKSEAJunAreaConStr str : junction) {
            Acoustics::FITKAbstractSEASubSys* subSys = _SEAModel->getSEASubSysManager()->getDataByID(str._subSysID);
            if (subSys == nullptr)continue;
            Acoustics::FITKAbstractSEASubSys::SEASubSysType type = subSys->getSEASubSysType();
            _ui->tableWidget_Connect->setRowCount(rowIndex + 1);
            QTableWidgetItem* item = new QTableWidgetItem();
            item->setText(subSys->getDataObjectName());
            item->setData(SEAAreaJunction_SubSysPos, subSys->getDataObjectID());
            item->setFlags(Qt::ItemIsEnabled);
            _ui->tableWidget_Connect->setItem(rowIndex, 0, item);
            rowIndex++;
        }
    }

    void SEAAreaJunctionDialog::updateLeaksTable(QList<Acoustics::FITKSEAJunAreaLeakStr>& leaks)
    {
        auto spectraManager = _physics->getFITKAcousticsSpectraManager();
        if (spectraManager == nullptr)return;
        _ui->tableWidget_Define->setRowCount(0);
        int rowIndex = 0;
        for (Acoustics::FITKSEAJunAreaLeakStr str : leaks) {
            _ui->tableWidget_Define->setRowCount(rowIndex + 1);
            QTableWidgetItem* item = new QTableWidgetItem();
            item->setText(str._name);
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            item->setData(SEAAreaJunction_DefineStrPos, QVariant::fromValue(str));
            _ui->tableWidget_Define->setItem(rowIndex, 0, item);

            QCheckBox* box = new QCheckBox();
            box->setChecked(str._isEnabled);
            _ui->tableWidget_Define->setCellWidget(rowIndex, 1, box);

            item = new QTableWidgetItem();
            QString type = "";
            switch (str._type){
            case Acoustics::FITKSEAJunAreaLeakStr::Rectangular: type = "Rectangular"; break;
            case Acoustics::FITKSEAJunAreaLeakStr::Circular: type = "Circular"; break;
            case Acoustics::FITKSEAJunAreaLeakStr::Slit: type = "Slit"; break;
            case Acoustics::FITKSEAJunAreaLeakStr::UserDefined: type = "UserDefined"; break;
            }
            item->setText(type);
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 2, item);

            item = new QTableWidgetItem();
            if (str._isLength == false)item->setText("");
            else item->setText(QString::number(str._length));
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 3, item);

            item = new QTableWidgetItem();
            if (str._isWidth == false)item->setText("");
            else item->setText(QString::number(str._width));
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 4, item);

            item = new QTableWidgetItem();
            if (str._isRadius == false)item->setText("");
            else item->setText(QString::number(str._radius));
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 5, item);

            item = new QTableWidgetItem();
            if (str._isDepth == false)item->setText("");
            else item->setText(QString::number(str._depth));
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 6, item);

            item = new QTableWidgetItem();
            item->setText(QString::number(str._area));
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 7, item);

            item = new QTableWidgetItem();
            if (str._isTLSpectrumID == false)item->setText("");
            else {
                auto specData = spectraManager->getDataByID(str._TLSpectrumID);
                if (specData) {
                    item->setText(specData->getDataObjectName());
                }
            }
            item->setFlags(Qt::ItemFlag::ItemIsEnabled);
            _ui->tableWidget_Define->setItem(rowIndex, 8, item);

            rowIndex++;
        }
    }

    QList<Acoustics::FITKSEAJunAreaLeakStr> SEAAreaJunctionDialog::getLeaksTable()
    {
        QList<Acoustics::FITKSEAJunAreaLeakStr> leakStrList = {};
        for (int i = 0; i < _ui->tableWidget_Define->rowCount(); i++) {
            QTableWidgetItem* item = _ui->tableWidget_Define->item(i, 0);
            if (item) {
                Acoustics::FITKSEAJunAreaLeakStr str = item->data(SEAAreaJunction_DefineStrPos).value<Acoustics::FITKSEAJunAreaLeakStr>();
                leakStrList.append(str);
            }
        }
        return leakStrList;
    }
}